﻿using System.Runtime.Remoting.Messaging;
using Microsoft.Practices.Unity;

namespace Gp.Examples.FullCalendar.Infrastructure
{
    public class UnityRequestLifetimeManager<T> : LifetimeManager
    {
        public override object GetValue()
        {
            var obj = CallContext.GetData(Key);
            return obj;
        }

        public override void SetValue(object newValue)
        {
            CallContext.SetData(Key, newValue);
        }

        public override void RemoveValue()
        {
            CallContext.SetData(Key, null);
        }

        public string Key
        {
            get
            {
                return typeof(T).AssemblyQualifiedName;
            }
        }
    }
}
